Page({

  /**
   * 页面的初始数据
   */
  data: {
    key: '',
    title: '',
    value: '',
    maxLength: 10,
    currentLength: -1
  },
  save() {
    if (this.data.key == 'act.originator') {
      this.setData({
        value: this.data.value.trim()
      });
      this.setData({
        currentLength: this.data.value.length
      });
      if (this.data.value == '') {
        wx.showToast({
          title: this.data.title + '不能为空',
          icon: 'none',
          duration: 2000
        })
        return;
      }
    }else{
      var value = this.data.value;
      if (!(/^[0-9]+.?[0-9]*$/.test(value))) {
        wx.showToast({
          title: '请输入正确的数字',
          icon: 'none',
          duration: 2000
        })
        return;
      }
      if (value >= 999999.99) {
        wx.showToast({
          title: '请填写999999.99以内的数字',
          icon: 'none',
          duration: 2000
        })
        return;
      }
      if (String(value).indexOf(".") > 0 && String(value).length - String(value).indexOf(".") - 1 > 2){
        wx.showToast({
          title: '最多只能输入两位小数',
          icon: 'none',
          duration: 2000
        })
        return;
      }
    }
    let pages = getCurrentPages(),
      prevPage = pages[pages.length - 2];
    prevPage.toggle(this.data.key, this.data.value);
    wx.navigateBack({
      delta: 1
    })
  },
  seatInput(e) {
    if (this.data.currentLength != -1) {
      var seat = e.detail.value,
        currentLength = e.detail.value.length;
      if (currentLength > this.data.maxLength) {
        wx.showToast({
          title: '输入文字数量已达到上限',
          icon: 'none',
          duration: 2000
        })
        return this.data.value;
      }
      this.setData({
        value: seat,
        currentLength: currentLength
      })
    } else {
      this.setData({
        value: e.detail.value
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let currentLength = -1;
    if (options.key == 'act.originator') {
      currentLength = options.value.length;
    }
    this.setData({
      key: options.key,
      value: options.value,
      currentLength: currentLength,
      title: options.title
    })
    wx.setNavigationBarTitle({
      title: options.title
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  }
})